<?php

namespace app\index\model;

use think\Model;
use think\Db;

class StudentModel extends Model
{
    /**查询列表
     * @return array|\PDOStatement|string|\think\Collection|\think\model\Collection
     */
    public function index(){
        $list = Db::table('student')->select();
        return $list;
    }

    /**实现添加功能
     * @param $data
     * @return $data
     */
    public function adds ($data){
        $adds = Db::table('student')->insert([
            'name' => $data['name'],
            'sex' => $data['sex'],
            'classes' => $data['classes'],
            'age' => $data['age'],
            'create_time' => time(),
            'update_time' => time()
        ]);

        return $data;
    }

    /** find查询单条数据
     * @param $id
     * @return array|\PDOStatement|string|Model|null
     */
    public function edit($id){
        $find = Db::table('student')->where('id' , $id )->find();
        return $find;
    }

    /**实现修改功能
     * @param $data
     * @return int|string
     */
    public function edits($data){
        $adds = Db::table('student')->where('id' , $data['id'] )->update([
            'name' => $data['name'],
            'sex' => $data['sex'],
            'classes' => $data['class'],
            'age' => $data['age'],
            'update_time' => time()
        ]);
        return $adds;
    }

    /**实现删除功能
     * @param $id
     * @return int
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function del($id){
        $del = Db::table('student' )->where( 'id' , $id )->delete();
        return $del;
    }

}